package cn.dapeng.utils;

import java.util.Arrays;
import java.util.Comparator;

public class ComparatorExample {


    static class Student {
        public int id;
        private String name;

        Student(int id, String name) {
            this.id = id;
            this.name = name;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    '}';
        }

    }

    public static void main(String[] args) {
        // 原生数据类型的排序
        int[] array = BuilderArray.builderArray(100, 20);
        Arrays.sort(array);
        BuilderArray.print(array);

        // 自定义数据类型的排序

        Student[] students = {new Student(9, "a"), new Student(8, "b"), new Student(2, "c"), new Student(3, "d")};

        Arrays.sort(students, Comparator.comparingInt(o -> o.id));

        //Arrays.sort(students, (o1, o2) -> o1.id - o2.id);
        for (Student student : students) {
            System.out.println(student);
        }
    }
}
